﻿using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Text;

namespace CPPEI.PM.Service.Model.Repository
{
    public class WorkStageRefRepository
    {
        private DbContext _dbContext;
        public WorkStageRefRepository(DbContext dbContext)
        {
            _dbContext = dbContext;
        }

        public WorkStageRef Get(Guid workSheetId, Guid workStageId)
        {
            return _dbContext.Set<WorkStageRef>().SingleOrDefault(p => p.WorkSheetId == workSheetId && p.WorkStageId == workStageId);
        }

        public WorkStageRef GetRoot(Guid workSheetId)
        {
            return _dbContext.Set<WorkStageRef>().SingleOrDefault(p => p.ParentWorkStageId == Guid.Empty && p.WorkSheetId == workSheetId);
        }

        public List<WorkStageRef> GetByParent(Guid workSheetId, Guid parentWorkStageId)
        {
            return _dbContext.Set<WorkStageRef>().Where(p => p.ParentWorkStageId == parentWorkStageId && p.WorkSheetId == workSheetId).ToList();
        }

        public void Create(WorkStageRef workStageRef)
        {
            _dbContext.Set<WorkStageRef>().Add(workStageRef);
        }
    }
}
